package project02.controller.deleteData;

import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import project02.dao.DateDataDao;
import project02.model.DateData;
import project02.model.UserInfo;

public class IndexController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(IndexController.class.getName());
    private DateDataDao dao = new DateDataDao();


    @Override
    public Navigation run() {

        UserInfo user = sessionScope("userInfo");

        if (!user.getPassword().equals(asString("password"))) {
            requestScope("result", "パスワードが一致しません.");
            return forward("../");
        }

        DateData entity = new DateData();
        entity = dao.find(asString("dataId"));
        dao.deletePersistentInTx(entity);

        requestScope("result", "削除しました.");

        return forward("../");
    }
}
